package com.wnxy.sk.product.controller;


import cn.hutool.core.bean.BeanUtil;
import com.wnxy.sk.common.result.Result;
import com.wnxy.sk.product.entity.Product;
import com.wnxy.sk.product.service.IProductService;
import com.wnxy.sk.product.vo.ProductVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 商品表 前端控制器
 * </p>
 *
 * @author Jet
 * @since 2022-10-11
 */
@RestController
@RequestMapping("/product")
@Api(tags = "商品模块")
public class ProductController {

    @Autowired
    private IProductService productService;

    @GetMapping("/{id}")
    @ApiOperation("根据id查询商品")
    public Result<ProductVo> findProductById(@PathVariable("id") Integer id){
        // 根据ID查询
        Product product = productService.getById(id);
        // 把Product对象转换为vo对象
        ProductVo productVo = BeanUtil.copyProperties(product, ProductVo.class);
        return Result.ok(productVo);
    }
}

